﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using Frogism.Core;
using System.Data.SqlClient;
namespace Frogism.Data {
    public class AccountLoader :LoaderBase<Account,IAccount>,Core.IAccountLoader{
        public AccountLoader(User user)
        {
            User = user;
        }
        protected User User
        {
            get;
            set;
        }
      private TransactionLoader _TransactionLoader;
      protected TransactionLoader TransactionLoader {
        get {
          if(_TransactionLoader == null) {
            _TransactionLoader = new TransactionLoader();
          }
          return _TransactionLoader;
        }
      }
      protected override IAccount GetEmptyObject() {
        return new Account();
      }
      protected override void FillObject(IAccount a,FriendlyReader reader) {
            
            a.Name = reader.String("Name");
            a.IsActive = reader.Bool("IsActive");
            a.AccountType = reader.Int("AccountTypeId");
            a.MaxValue = reader.Decimal("MaxValue");
            a.MinValue = reader.Decimal("MinValue");
            a.NextGoalValue = reader.Decimal("NextGoalValue");
            a.Purpose = reader.String("Purpose");
            /*
            a.IsActive = (bool)reader["IsActive"];
            a.NextGoalValue = (decimal)reader["Goal"];
             */
            //a.Id = -99999;

            ((Account)a).SetTransactions(TransactionLoader.TransactionByAccount(a.Id));
        }
       

        protected override string ProcNameGetAll {
          get { return "AccountGetAll"; }
        }

        protected override string ProcNameGetById {
          get { return "AccountGetById"; }
        }
    }
}
